package com.example.thread.d1线程常用的api;

public class MyThread {
    public static void main(String[] args) {
        MyThreadTest m1 = new MyThreadTest("1号线程");
//        m1.setName("1号线程");
        m1.start();
        // 获取线程的名字
        System.out.println(m1.getName()); // Thread-0
        // 哪个线程调用就会获取哪个线程的名字
        System.out.println(Thread.currentThread().getName()); // main
        for (int i = 0; i < 5; i++) {
            System.out.println("主线程"+i);
        }
    }
}
class MyThreadTest extends Thread {
    public MyThreadTest(String name) {
        super(name);
    }
    @Override
    public void run() {
        for (int i = 0; i < 5; i++) {
            System.out.println(Thread.currentThread().getName()+"子线程"+i);
        }
    }
}
